package com.zhuss.advice.processor;

import com.zhuss.advice.db.dao.ext.ProposalDao;
import com.zhuss.advice.db.entity.Proposal;
import com.zhuss.bean.bo.advice.proposal.DeleteProposalBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: zhushanshuo
 * @Date: 2020/3/6 14:53
 */
@Component("proposalDelete")
public class ProposalDelete extends AbstractProcessor<Object, DeleteProposalBo> implements Processor<Object, DeleteProposalBo> {

    @Autowired
    private ProposalDao proposalDao;

    @Override
    public Object process(DeleteProposalBo bo) throws WpsException {
        Proposal p = new Proposal();
        p.setProposalId(bo.getProposalId());
        p.setDeleted(bo.getDeleted());

        p.setModifier(bo.getConcurrentUserName());
        p.setModifierId(bo.getConcurrentUserId());
        p.setModifyTime(new Date());
        proposalDao.delete(p);
        return null;
    }

    @Override
    public Object log(DeleteProposalBo param) throws WpsException {
        OpLog record = new OpLog();
        record.setMoudle(MoudleEnum.意见建议.key());
        record.setAction(LogActionEnum.意见建议删除.key());
        record.setTargetId(param.getProposalId());
//        record.setTargetName(param.getProposalNo());
        record.setContent("参数: " + JsonUtil.toJson(param));
        record.setReason(param.getExceptionReason());

        record.setCreatorId(param.getConcurrentUserId());
        record.setCreator(param.getConcurrentUserName());
        record.setCreateTime(new Date());
        log(record);
        return null;
    }

    @Override
    public void check(DeleteProposalBo deleteProposalBo) throws WpsException {

    }
}
